<template>
  <div class="app-container">
    <MyHeader background="#ff5151" color="#DFD8CA" title="淘金"></MyHeader>
    <MyGoods :goods="item" v-for="item in list" :key="item.id"></MyGoods>
    <MyFooter @changeAll="allFn" :arr="list"></MyFooter>
  </div>
</template>

<script>
import MyHeader from "./components/MyHeader.vue";
import MyGoods from "./components/MyGoods.vue";
import MyFooter from "./components/MyFooter.vue";
export default {
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  name: "ShopcarApp",

  data() {
    return {
      list: [],
    };
  },

  created() {
    // 全局属性$axios
    this.$axios({
      url: "/api/cart",
    }).then((res) => {
      console.log(res);
      this.list = res.data.list;
    });
  },

  mounted() {},

  methods: {
    allFn(bool) {
      this.list.forEach((goods) => (goods.goods_state = bool));
    },
  },
};
</script>

<style lang="less" scoped>
.app-container {
  padding-top: 45px;
}
</style>